package cn.com.dycc.party_work.education_dept.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_work.education_dept.entity.EducationDept;
import cn.com.dycc.party_work.education_dept.entity.EducationDeptInfo;
import cn.com.dycc.party_work.education_dept.param.FindEducationDeptParam;
import cn.com.dycc.party_work.education_dept.service.EduDeptNotFoundException;
import cn.com.dycc.party_work.education_dept.service.EducationDeptService;
import cn.com.dycc.util.JsonObjectResult;

/**
 * 
 * Description: 党员教育控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月21日 上午8:54:05.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/education/dept")
public class EducationDeptController extends BaseController {
	
	@Resource
	private EducationDeptService eduService;

	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addEduDept(EducationDept eduDept,HttpServletRequest req){
		int n = eduService.addEduDept(eduDept, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/addall.do")
	@ResponseBody
	public JsonObjectResult addAllEduDept(String education_id, String[] dept_ids, HttpServletRequest req){
		int n = eduService.addAllEduDept(education_id,dept_ids, req);
		return new JsonObjectResult(n);
	}
	
		
	@RequestMapping("/findone.do")
	@ResponseBody
	public JsonObjectResult findEduDeptById(String education_id,String dept_id,HttpServletRequest req){
		EducationDeptInfo eduDept = eduService.findEduDeptById(education_id,dept_id,req);
		return new JsonObjectResult(eduDept);
	}
	
	@RequestMapping("/findall.do")
	@ResponseBody
	public JsonObjectResult findAllEduDept(FindEducationDeptParam param,HttpServletRequest req){
		String count = eduService.findAllEduDeptCount(param, req);
		List<EducationDeptInfo> list = eduService.findAllEduDept(param,req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteEduDept(String education_id,String dept_id,HttpServletRequest req){
		int n = eduService.deleteEduDept(education_id,dept_id,req);
		return new JsonObjectResult(n);
	}
	@ExceptionHandler(EduDeptNotFoundException.class)
	@ResponseBody
	public JsonObjectResult eduException(EduDeptNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(77,e);
	}
}
